package com.xbongbong.paas.help.menu;

import com.xbongbong.admin.pojo.dto.MirrorRollBackDTO;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasAppEntity;
import com.xbongbong.paas.domain.entity.PaasFormEntity;
import com.xbongbong.paas.pojo.dto.MenuFormAddDTO;
import com.xbongbong.paas.service.PaasMenuService;
import com.xbongbong.paas.service.init.AbstractInitMenuHelp;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.pro.enums.AccessLinkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.menu.enums.GroupMessageMenuEnum;
import com.xbongbong.pro.enums.menu.enums.SystemAppMenuEnum;
import com.xbongbong.pro.menu.pojo.dto.MenuFormAddBatchDTO;
import com.xbongbong.pro.menu.pojo.dto.MenuInitDTO;
import com.xbongbong.pro.menu.pojo.vo.MenuInitVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author 吴峰
 * @date 2022/11/03 14:16
 */
@Component
public class InitGroupMessageMenuHelp extends AbstractInitMenuHelp {
    @Resource
    private PaasMenuService paasMenuService;



    @Override
    public List<String> alias() {
        return Arrays.asList(SystemAppMenuEnum.GROUP_MESSAGE.getAlias());
    }

    @Override
    public MenuInitVO initApp(MenuInitDTO menuInitDTO, Map<String, PaasAppEntity> appMap) throws XbbException {
        MenuFormAddBatchDTO messageAddBatchDTO = new MenuFormAddBatchDTO();
        BeanUtil.copyProperties(menuInitDTO, messageAddBatchDTO);
        Long appId = appMap.get(SystemAppMenuEnum.GROUP_MESSAGE.getAlias()).getId();
        messageAddBatchDTO.setAppId(appId);
        List<MenuFormAddDTO> messageMenuList = new ArrayList<>();
        for(GroupMessageMenuEnum messageMenuEnum: GroupMessageMenuEnum.values()){
            if(PaasConstant.HOME_STRING.equals(messageMenuEnum.getBelong())){
                MenuFormAddDTO menuFormAddDTO = new MenuFormAddDTO();
                BeanUtil.copyProperties(menuInitDTO, menuFormAddDTO);
                menuFormAddDTO.setAppId(appId);
                menuFormAddDTO.setParentId(0L);
                menuFormAddDTO.setSaasMark(SaasMarkEnum.SAAS.getCode());
                menuFormAddDTO.setAlias(messageMenuEnum.getAlias());
                menuFormAddDTO.setName(messageMenuEnum.getName());
                AccessLinkEnum accessLinkEnum = messageMenuEnum.getAccessLinkEnum();
                menuFormAddDTO.setIcon(accessLinkEnum.getIcon());
                menuFormAddDTO.setColor(accessLinkEnum.getColor());
                menuFormAddDTO.setUrl(accessLinkEnum.getUrl());
                menuFormAddDTO.setMobileUrl(accessLinkEnum.getMobileUrl());
                menuFormAddDTO.setType(messageMenuEnum.getType());
                messageMenuList.add(menuFormAddDTO);
            }
        }
        messageAddBatchDTO.setMenuList(messageMenuList);
        paasMenuService.addBatchFormMenu(messageAddBatchDTO);
        MenuInitVO menuInitVO = new MenuInitVO();
        return menuInitVO;
    }

    @Override
    public MenuInitVO initMenu(MenuInitDTO menuInitDTO, Map<String, PaasAppEntity> appMap) throws XbbException {
        return null;
    }

    @Override
    public void rollBackInit(MirrorRollBackDTO mirrorRollBackDTO, List<Long> installFormList, PaasFormEntity productFormEntity) throws XbbException {

    }
}
